|
|
|
|
|
|
|
Congratulations! You just wrote your first Visual Basic code. |
|
|
|
|
|
|
|
|
Specifying Event Procedures |
|
|
|
|
|
|
|
|
Look at the two drop-down list boxes near the top of the Code window, as shown in Figure 2.18. The Object box (the one on the left) lists all the objects that have been placed on the current form, as well as the form itself. The Procedure box (on the right) lists all the events that apply to whichever object is currently selected in the Object box. Using these two drop-down list boxes enables you to navigate to any portion of the Code window. Think of the code for a particular form as one long text file; the Code window is a navigation tool that helps you quickly display a specific object/event combination. |
|
|
|
|
|
|
|
|
Figure 2.18
The Exit button's Click event procedure will cause
the program to end when the button is clicked. |
|
|
|
|
|
|
|
|
When you double-click a control at design time, the Code window automatically opens to the default event for the control you clicked, unless some event other than the default already has code in its event procedure. In that case, the event procedure that contains code is selected, in case you want to edit that code. Of course, you can use the Object and Procedure boxes at any time to quickly locate the desired object/event combination. |
|
|
|
|
| |
|
|
|
|
In addition to double-clicking an object, you can also open the Code window by pressing F7, by clicking the View Code button in the Project window, or by selecting View, Code from the menu. |
|
|
|
|
|
|
|
|
|
|
Now that you've properly coded the Exit button to end the application, all that remains is to code the Calculate Payment button. Its function is to calculate the monthly payment amount, based on the information the user has supplied. This code will be written as the Click event procedure for the command button cmdCalculate. You could display the cmdCalculate button's Click event procedure by bringing the form designer to the front and double-clicking cmdCalculate; however, because the Code window is already open, it would be more efficient to drop down the Code window's Object box and select cmdCalculate. This displays the procedure cmdCalculate_Click in the Code window. |
|
|
|
|
|